<?php PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/comment.css\" rel=\"stylesheet\">");?>
<?php PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/postview.css\" rel=\"stylesheet\">");?>
<?php PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/forum.css\" rel=\"stylesheet\">");?>
<?php PageUtil::addVar("title",$post[0]['title']." - www.Truck.co.th");?>
<?php $usr_data = $this->session->userdata("user_data"); ?>
<!-- tiny mce -->
<script src="<?php echo base_url('/themes/Theme01/js/tinymce/tinymce.dev.js'); ?>"></script>
<script>
  tinymce.init({
    selector: "textarea#elm1",
    theme: "modern",
    menubar : false,
    plugins: [
      "advlist autolink  image lists charmap print preview hr anchor pagebreak spellchecker",
      "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
      "save table contextmenu directionality emoticons template paste textcolor importcss"
    ],
    add_unload_trigger: false,

    toolbar: "insertfile undo redo | bold italic | alignleft aligncenter alignright alignjustify | forecolor fullpage backcolor  preview  ",

    image_advtab: true,

    style_formats: [
      {title: 'Bold text', format: 'h1'},
      {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
      {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
      {title: 'Example 1', inline: 'span', classes: 'example1'},
      {title: 'Example 2', inline: 'span', classes: 'example2'},
      {title: 'Table styles'},
      {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
  });
</script>
<!-- end tiny mce -->
<!-- style image galery box swipe  -->
    <link href="<?php echo $jspath.'/photoswipe/photoswipe.css'; ?>" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="<?php echo $jspath.'/photoswipe/lib/klass.min.js'; ?>"></script>
    <script type="text/javascript" src="<?php echo $jspath.'/photoswipe/code.photoswipe.jquery-3.0.5.min.js'; ?>"></script>
    <script type="text/javascript">
        (function(window, $, PhotoSwipe){
            $(document).ready(function(){
                var options = {
                    imageScaleMethod: "fitNoUpscale"
                };
                $(".gallery a").photoSwipe(options);
            });
        }(window, window.jQuery, window.Code.PhotoSwipe));
    </script>
<!-- end -->

<script type="text/javascript">
$(function (){
    $('.imggroup').mouseover(function() {
        var src =   $(this).parent("a").data("image");
        var src2 =  $(this).parent("a").attr("href");
        var show = $(this).attr("class");
      $('#large_image').html('<div class="gallery"><a href="'+src2+'"><img src="'+src+'" alt="หมวดหมู่ : ภาพหน้าปก" /></a></div>');
      (function(window, $, PhotoSwipe){
            $(document).ready(function(){
                var options = {
                    imageScaleMethod: "fitNoUpscale"
                };
                $(".gallery a").photoSwipe(options);
            });
        }(window, window.jQuery, window.Code.PhotoSwipe));
    });
});
</script>

<section class="container_pos allcontainer">
    <nav class="left_content breadcrumb">
        <?php echo $breadcrumb;?>
    </nav>
    <section class="container_left">
        <section class="container img_container padding5px">
            <section class="title">
                <a href="<?php echo base_url("forum/view/".$post[0]['url']);?>">
                    <h1>
                <?php echo $post[0]['title'];?>
                    </h1>
                </a>
            </section>

            <section class="post-detail">
                <span>โดย <?php echo $post[0]["username"];?>, เมื่อ <?php echo Util::ezDate($post[0]['cr_date']); ?></span>
                <?php
                if(!empty($userdata) && ($post[0]['usr_id'] == $userdata['id'] OR $userdata['group'] == 2)){
                ?>
                
                <section class="pull-right">
                    <a href="<?php echo base_url("forum/edit/".$post[0]['id']);?>" class="btn btn-small"><i class="icon-pencil"></i> แก้ไข</a>
                    <a href="<?php echo base_url("forum/delete/".$post[0]['id']);?>" class="btn btn-small" onClick="return confirm('คุณแน่ใจว่าจะลบใช่หรือไม่');"><i class="icon-trash"></i> ลบ</a>
                </section>
                
                <?php
                }
                ?>
            </section>
            <div class="fb-like" style="margin-top:5px;" data-href="<?php echo base_url("forum/view/".$post[0]['url']);?>" data-width="100%" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
            
            <section class="post-image">
                    <?php
                        if(!empty($post[0]["images"])){
                                ?>
                            <?php
                                ?>
                                <div id="large_image">
                                    <div class="gallery"><!-- use jqly image-->
                                        <a href="<?php echo base_url($post[0]["images"][0]['filepath']);?>"><img src="<?php echo base_url($post[0]["images"][0]['medium']);?>" alt="<?php echo $post[0]['title'];?>" /></a>
                                    </div>
                                </div>
                        <?php
                        }else{
                        echo "<img src=\"".$imagepath."/not_available.jpg\"/>";
                        }
                    ?>

                    <!-- tam mai del sestion  -->
                    <div id="group">
                        <div class="gallery" >
                        <?php if(!empty($post[0]["images"])) { ?>
                        <section class="title">ภาพประกอบ</section>
                        <?php
                                foreach($post[0]["images"] as $key => $img1) :
                        ?>
                                    <a href="<?php echo base_url($img1['filepath']);?>" data-image="<?php echo base_url($img1["medium"]); ?>"><img src="<?php echo base_url($img1['small']);?>"  class="imggroup" alt="<?php echo $post[0]['title'];?>"/> </a>
                        <?php
                                endforeach;
                            }
                        ?>
                        </div>
                    </div>
                <!-- end -->
            </section>
        </section>
    </section>

    <section class="container_right">
        <section class="container content_container padding5px">
            <h1 class="title">คำอธิบาย</h1>
            <article>
                    <?php echo $post[0]['content'];?>
            </article>
        </section>
    </section>
</section>
<?php PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/widget.css\" rel=\"stylesheet\">");
  if(!empty($listpost)){
?>
<div class="activities_block container widget">
  <h2><img src="<?php echo $imagepath;?>/icon_activities.png" alt="กิจกรรม">Truck Service</h2>
    <?php
        foreach ($listpost as $key => $value) {
    ?>
      <div class="activities-list">
        <?php
          if(!empty($value["images"][0]["small"])){
            ?>
            <a href="<?php echo base_url('forum/view/'.$value["url"]);?>" target="_blank"><img src="<?php echo base_url($value["images"][0]["small"])?>" /></a>
            <?php
          }else{
            ?>
            <a href="<?php echo base_url('forum/view/'.$value["url"]);?>" target="_blank"><img src="<?php echo $imagepath."/not_available-2.jpg"?>" /></a>
            <?php
          }
        ?>
        <a class="title-link" href="<?php echo base_url('forum/view/'.$value["url"]);?>" target="_blank"><strong><?php echo $value["title"];?></strong></a>
        <div class="muted"><small><?php echo mb_substr(strip_tags($value["content"]), 0, 60,"UTF-8");?>...</small></div>
      </div>
    <?php 
        }
    ?>
</div>
<?php
  }
?>
<section class="left_content">
<form action="<?php echo base_url('comment/add_comment'); ?>" method="post">
<section class="commentArea">
<h3>Comment</h3>
    <?php
        if(!empty($comments)){
    ?>

    <?php foreach($comments as $key => $value) :
    if($value['parent_id']==0  AND ($value['status'] == 1 OR $userdata['group'] == 2)){
        ?>
        <section class="first_comment">
            <section class="middle_bar">
                <section class="pic_box">
                    <img src="<?php echo base_url('themes/Theme01/images/user.png');?>" width="100"height="100">
                    <p><?php echo $value['firstname'];?></p>
                </section>
                <?php if($value['status'] == 1){ ?>   <!--Status == 1  Comment -->
                <section class="comment">
                    <section class="point"></section>
                        <p><?php
                            $content=wordwrap($value['content'],50,"\n",TRUE);
                            echo "$content\n";
                        ?></p>
                    <section class="reply_box">
                        <b><a href="<?php echo base_url('comment/reply/'.$value['id']);?>"title="ตอบกลับ">Reply</a></b>
                        <?php
                        if(!empty($userdata)){
                            if($userdata['group']==2 OR $value['usr_id'] == $userdata['id']){
                        ?>
                        <section class = "option_edit">
                            <a href="<?php echo base_url('comment/edit_comment/'.$value['id']);?>">
                            <img src ="<?php echo base_url('themes/Theme01/images/edit.png');?>"width="25"height="30"title="แก้ไขคอมเม้น"></a>
                        </section>
                        <section class = "option_delete">
                            <a href="<?php echo base_url('comment/delete_comment/'.$value['id']);?>">
                                <img src ="<?php echo base_url('themes/Theme01/images/x.png');?>"width="25"height="30"title="ลบคอมเม้น"></a>
                        </section>
                    </section>
                </section>
                        <?php
                        }} }elseif($value['status'] == 0 AND $userdata['group'] == 2){    //Status == Comment Satus == 0 Admin
                        ?>

                <section class="commentdel">
                    <section class="point"></section>
                        <p><?php
                            $content=wordwrap($value['content'],50,"\n",TRUE);
                            echo "$content\n";
                        ?></p>
                    <section class="reply_box">
                        <b><a href="<?php echo base_url('comment/delete_comment/'.$value['id']);?>"title="ตอบกลับ">UNBAND</a></b>
                    </section>
                </section>
                        <?php
                        }
                        ?>
            </section>
        <section class="second_middle_bar">
            <?php foreach ($comments as $valuereply  ) {
                if($value['id']==$valuereply['parent_id']  AND ( $valuereply['status'] == 1 OR $userdata['group'] == 2)) {
            ?>
                <section class="first_comment2">
                    <section class="middle_bar2">
                        <section class="pic_box2">
                                <img src="<?php echo base_url('themes/Theme01/images/user.png');?>"width="100"height="100">
                                <p><?php echo $valuereply['firstname'];?></p>
                        </section>
                        <?php if($valuereply['status'] == 1){ //comment LV 2 ?>
                        <section class="comment2">
                            <section class="point"></section>
                            <p><?php
                                $content=wordwrap($valuereply['content'],50,"\n",TRUE);
                                echo "$content\n";
                            ?></p>

                            <section class="reply_box">
                                <b><a href="<?php echo base_url('comment/reply/'.$valuereply['id']);?>"title="ตอบกลับ">Reply</a></b>
                                <?php
                                    if(!empty($userdata)){
                                        if($userdata['group']==2 OR $valuereply['usr_id']==$userdata['id']){
                                ?>
                                <section class = "option_edit">
                                    <a href="<?php echo base_url('comment/edit_comment/'.$valuereply['id']);?>">
                                    <img src ="<?php echo base_url('themes/Theme01/images/edit.png');?>"width="25"height="30"title="แก้ไขคอมเม้น"></a>
                                </section>
                                <section class = "option_delete">
                                    <a href="<?php echo base_url('comment/delete_comment/'.$valuereply['id']);?>">
                                        <img src ="<?php echo base_url('themes/Theme01/images/x.png');?>"width="25"height="30"title="ลบคอมเม้น"></a>
                                </section>
                            </section>
                        </section>
                                <?php
                                }} }else if($valuereply['status'] == 0 AND $userdata['group']==2){  ?>
                                        <section class="commentdel2">
                                        <section class="point"></section>
                                            <p><?php
                                                $content=wordwrap($valuereply['content'],50,"\n",TRUE);
                                                echo "$content\n";
                                            ?></p>
                                        <section class="reply_box">
                                            <b><a href="<?php echo base_url('comment/delete_comment/'.$valuereply['id']);?>"title="ตอบกลับ">UNBAND</a></b>
                                        </section>
                                    </section>
                                <?php
                                }
                                ?>
                    </section>


                    <section class="third_middle_bar">
                        <?php foreach ($comment as $valuereply3 ) {
                            if($valuereply['id']==$valuereply3['parent_id'] AND ( $valuereply3['status'] == 1 OR $userdata['group'] == 2)) {
                        ?>
                        <section class="first_comment3">
                            <section class="middle_bar3">
                                <section class="pic_box3">
                                    <img src="<?php echo base_url('themes/Theme01/images/user.png');?>"width="100"height="100">
                                    <p><?php echo $valuereply3['firstname'];?></p>
                                </section>
                                <?php if($valuereply3['status'] == 1){ //comment LV 3?>
                                <section class="comment3">
                                    <section class="point"></section>
                                        <p><?php
                                            $content=wordwrap($valuereply3['content'],50,"\n",TRUE);
                                            echo "$content\n";
                                        ?></p>
                                    <section class="reply_box">
                                        <b><a href="<?php echo base_url('comment/reply/'.$valuereply3['id']);?>"title="ตอบกลับ">Reply</a></b>
                                        <?php
                                            if(!empty($userdata)){
                                                if($userdata['group']==2 OR $valuereply3['usr_id']==$userdata['id']){
                                        ?>
                                        <section class = "option_edit">
                                            <a href="<?php echo base_url('comment/edit_comment/'.$valuereply3['id']);?>">
                                            <img src ="<?php echo base_url('themes/Theme01/images/edit.png');?>"width="25"height="30"title="แก้ไขคอมเม้น"></a>
                                        </section>
                                        <section class = "option_delete">
                                            <a href="<?php echo base_url('comment/delete_comment/'.$valuereply3['id']);?>">
                                                <img src ="<?php echo base_url('themes/Theme01/images/x.png');?>"width="25"height="30"title="ลบคอมเม้น"></a>
                                        </section>
                                    </section>
                                </section>
                                        <?php
                                        }} }elseif($valuereply3['status'] == 0 AND $userdata['group']==2){
                                        ?>

                                        <section class="commentdel3">
                                        <section class="point"></section>
                                            <p><?php
                                            $content=wordwrap($valuereply3['content'],50,"\n",TRUE);
                                            echo "$content\n";
                                        ?></p>
                                        <section class="reply_box">
                                            <b><a href="<?php echo base_url('comment/delete_comment/'.$valuereply3['id']);?>"title="ตอบกลับ">UNBAND</a></b>
                                        </section>
                                    </section>
                                        <?php
                                        }
                                        ?>

                            </section>
                            <section class="end_middle_bar">
                                <?php foreach ($comment as $valuereplys ) {
                                    if($valuereply3['id']==$valuereplys['parent_id'] AND ($valuereplys['status'] == 1 OR $userdata['group'] == 2)) {
                                ?>
                                <section class="first_comments">
                                    <section class="middle_bars">
                                        <section class="pic_box3">
                                            <img src="<?php echo base_url('themes/Theme01/images/user.png');?>"width="100"height="100">
                                            <p><?php echo $valuereplys['firstname'];?></p>
                                        </section>
                                        <?php if($valuereplys['status'] == 1){ //comment LV 4?>
                                        <section class="comments">
                                            <section class="point"></section>
                                            <p><?php
                                                $content=wordwrap($valuereplys['content'],50,"\n",TRUE);
                                                echo "$content\n";
                                            ?></p>
                                            <section class="reply_box">
                                                <?php
                                                    if(!empty($userdata)){
                                                        if($userdata['group']==2 OR $valuereplys['usr_id']==$userdata['id']){
                                                ?>
                                                <section class = "option_edit">
                                                    <a href="<?php echo base_url('comment/edit_comment/'.$valuereplys['id']);?>">
                                                    <img src ="<?php echo base_url('themes/Theme01/images/edit.png');?>"width="25"height="30"title="แก้ไขคอมเม้น"></a>
                                                </section>
                                                <section class = "option_delete">
                                                    <a href="<?php echo base_url('comment/delete_comment/'.$valuereplys['id']);?>">
                                                        <img src ="<?php echo base_url('themes/Theme01/images/x.png');?>"width="25"height="30"title="ลบคอมเม้น"></a>
                                                </section>
                                                </section>
                                        </section>
                                                <?php
                                                }} }elseif($valuereplys['status'] == 0 AND $userdata['group']==2){
                                                ?>

                                                <section class="commentdel3">
                                                <section class="point"></section>
                                                    <p><?php
                                                    $content=wordwrap($valuereplys['content'],50,"\n",TRUE);
                                                    echo "$content\n";
                                                ?></p>
                                                <section class="reply_box">
                                                    <b><a href="<?php echo base_url('comment/delete_comment/'.$valuereplys['id']);?>"title="ตอบกลับ">UNBAND</a></b>
                                                </section>
                                                </section>




                                                <?php
                                                }
                                                ?>

                                    </section>
                                </section>
                                <?php
                                 }  }
                                 ?>
                    </section>
                            </section>

                        <?php
                         }  }
                         ?>
                    </section>
                </section>

            <?php

             }  }
             ?>
        </section>
    </section><br/>
    <?php } endforeach; ?>
    </section>
    <?php }else{?>

<section class="alert_area">
        <section class="alert_detail">
            <p class="text-center">ยังไม่มีความคิดเห็น</p>
        </section>
</section>
<?php
}
if(!empty($usr_data)){
?>
<legend>Post new comment</legend>

<section class="box_area">
    <input type="hidden" name="pos_id"  value="<?php echo $post[0]['id'] ?>" />
    <input type="hidden" name="title"  value="<?php echo $post[0]['title'] ?>" />
    <input type="hidden" name="type"  value="forum" />
<p><textarea id="elm1" name="content" cols="150" rows="10" size="100" type="text"></textarea></p><br />
<button type="submit" class="btn btn-primary" id="submitbtn">แสดงความคิดเห็น</button>
</section>
<?php
}else{
?>
<section class="alert_area">
    <section class="alert_bar">
        <p>แจ้งเตือน</p>
    </section>
        <section class="alert_detail">
            <p>ต้องการแสดงความคิดเห็นกรุณาล็อคอิน แต่ถ้ายังไม่ได้สมัครสมาชิกคลิกสมัครสมาชิก<p>
            <section class="button_log">
                <a href="<?php echo base_url('user'); ?>" ><button type="button" class="btn btn-primary">ล็อคอิน</button></a>&nbsp;&nbsp;&nbsp;<a href="<?php echo base_url('user/register'); ?>" ><button type="button" class="btn btn-primary" id="button_reg">สมัครสมาชิก</button></a>
            </section>
        </section>
</section>
<?php
}
?>
</form>
</section>